package com.lxy.equipment.controller;

import com.lxy.common.domain.common.R;
import com.lxy.common.domain.dto.MaintenanceScheduleDTO;
import com.lxy.common.domain.dto.MaintenanceUsersDTO;
import com.lxy.common.domain.po.Repair;
import com.lxy.common.domain.vo.AlertsVO;
import com.lxy.common.domain.vo.MaintenanceSchedulesVO;
import com.lxy.common.domain.vo.RepairUserVO;
import com.lxy.common.domain.vo.RobotVO;
import com.lxy.equipment.domain.vo.CompletedRepairVO;
import com.lxy.equipment.domain.vo.EquipmentVO;
import com.lxy.equipment.domain.vo.RepairVO;
import com.lxy.equipment.service.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;



@Api("设备相关接口")
@RestController
@RequiredArgsConstructor
@RequestMapping("/equipment")
public class EquipmentController {

    private final EquipmentService equipmentService;
    private final RepairService repairService;
    private final CompleteRepairService completeRepairService;
    private final AlertsService alertsService;
    private final MaintenanceSchedulesService maintenanceSchedulesService;
    private final MaintenanceUsersService maintenanceUsersService;


    @ApiOperation("获得所有设备名字")
    @GetMapping("/getAllEquipment")
    public R<List<EquipmentVO>> getAllEquipment(){
        //不需要权限，所有人都可以使用
        return equipmentService.getAllEquipment();
    }

    @ApiOperation("获得自己的维修订单（维修人员）")
    @GetMapping("/getMyRepair")
    public R<List<RepairVO>> getMyRepair (){
        return repairService.getMyRepair();
    }

    @ApiOperation("获得自己的历史维修订单（维修人员）")
    @GetMapping("/getMyCompletedRepair")
    public R<List<CompletedRepairVO>> getMyCompletedRepair(){
        return completeRepairService.getMyCompletedRepair();
    }

    @ApiOperation("生成预警单")
    @PostMapping("/sendAlerts")
    public R sendAlerts(@RequestBody RobotVO robotVO){
        return alertsService.sendAlerts(robotVO);
    }

    @ApiOperation("查看机器人预警（设备管理员）")
    @GetMapping("/showAlerts")
    public R<List<AlertsVO>> showAlerts(){
        return alertsService.showAlerts();
    }


    @ApiOperation("指派维修人员查看预警（生成维修单）")
    @GetMapping("/alertUser")
    public R alertUser(@RequestParam("alertsId") Long alertsId,@RequestParam("userId") Long userId ){
        return alertsService.alertUser(alertsId,userId);
    }

    @ApiOperation("更改维修单状态为维修中(点击开始维修)")
    @GetMapping("/changeRepairStatus")
    public R changeRepairStatus(@RequestParam("repairId") Long repairId){
        return repairService.changeRepairStatus(repairId);
    }

    @ApiOperation("新建维修计划")
    @PostMapping("/addMaintenanceSchedule")
    public R addMaintenanceSchedule(@RequestBody MaintenanceScheduleDTO maintenanceScheduleDTO){
        return  maintenanceSchedulesService.addMaintenanceSchedule(maintenanceScheduleDTO);
    }

    @ApiOperation("给维修人员安排每日维修任务")
    @PostMapping("/arrangementMaintenanceSchedule")
    public R arrangementMaintenanceSchedule(@RequestBody MaintenanceUsersDTO maintenanceUsersDTO){
        return maintenanceUsersService.arrangementMaintenanceSchedule(maintenanceUsersDTO);
    }

    @ApiOperation("新增维护订单的获取人员接口（排除这个订单已有的人员）")
    @GetMapping("/getRepairUsers")
    public R<List<RepairUserVO>> getRepairUsers(@RequestParam("maintenanceId") Long maintenanceId){
        return maintenanceUsersService.getRepairUsers(maintenanceId);
    }

    @ApiOperation("删除维护计划的人员")
    @DeleteMapping("/deleteMaintenanceUsers")
    public R deleteMaintenanceUsers(@RequestBody MaintenanceUsersDTO maintenanceUsersDTO){
        return maintenanceUsersService.deleteMaintenanceUsers(maintenanceUsersDTO);
    }

    @ApiOperation("删除维护计划")
    @DeleteMapping("/deleteMaintenanceSchedule")
    public R deleteMaintenanceSchedule(@RequestParam("maintenanceId") Long maintenanceId){
        return maintenanceSchedulesService.deleteMaintenanceSchedule(maintenanceId);
    }

    @ApiOperation("查看所有维护订单（设备管理员）")
    @GetMapping("/getAllMaintenanceSchedule")
    public R<List<MaintenanceSchedulesVO>> getAllMaintenanceSchedule(){
        return maintenanceSchedulesService.getAllMaintenanceSchedule();
    }

    @ApiOperation("修改维护计划（设备管理员）")
    @PostMapping("/updateMaintenanceSchedule")
    public R updateMaintenanceSchedule(@RequestBody MaintenanceSchedulesVO maintenanceSchedulesVO){
        return maintenanceSchedulesService.updateMaintenanceSchedule(maintenanceSchedulesVO);
    }

    @ApiOperation("查看自己的维护计划（维修人员）")
    @GetMapping("/getMyMaintenanceSchedules")
    public R<List<MaintenanceSchedulesVO>> getMyMaintenanceSchedules(@RequestParam("userId") Long userId){
        return maintenanceSchedulesService.getMyMaintenanceSchedules(userId);
    }

    @ApiOperation("删除维修订单中的userId")
    @GetMapping("/deleteRepairUser")
    public R deleteRepairUser(@RequestParam("userId")Long userId){
        return repairService.deleteRepairUser(userId);
    }

    @ApiOperation("查看所有维修订单")
    @GetMapping("/getAllRepair")
    public R<List<Repair>> getAllRepair(){
        return repairService.getAllRepair();
    }
}
